package com.ddzh.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ddzh.pojo.Role;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.* from user_role_t ur left join role_t r on r.id=ur.role_id where ur.user_id=#{userId}")
    List<Role> findByUserId(@Param("userId") Long userId);

    @Select("select * from role_t where role_name=#{roleName}")
    Role findByRoleName(@Param("roleName")String roleName);

    @Select("select * from role_t where role_code=#{roleCode}")
    Role findByRoleCode(@Param("roleCode")String roleCode);

    @Select("select rt.role_name\n" +
            "from user_role_t urt left join role_t rt on urt.role_id=rt.id\n" +
            "where urt.user_id=#{userId}")
    List<String> findRoleNameByUserId(@Param("userId")Long userId);
}
